// 购物车模块
export default {
  namespaced: true,
  state() {
    return {
      // 购物车列表数据
      cartList: [],
      // 购物车统计数据
      cartTotal: {}
    }
  },
  getters: {
    // 建立快捷访问
    goodsCount: state => state.cartTotal.goodsCount,
    checkedGoodsAmount: state => state.cartTotal.checkedGoodsAmount,
    checkedGoodsCount: state => state.cartTotal.checkedGoodsCount,
    goodsAmount: state => state.cartTotal.goodsAmount,
  },
  mutations: {
    // 设置购物车数据
    setCartData(state, data) {
      state.cartList = data.cartList
      state.cartTotal = data.cartTotal
    }
  },
  actions: {
    // 获取购物车数据
    async getInitData(context) {
      let res = await uni.$http.get('/cart/index')
      console.log(res);
      context.commit('setCartData', res)
    }
  }
}
